<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
<!--<![endif]-->
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>

<head>
    <meta charset="utf-8" />
    <%@include file="../common/taglib.jsp"%>
    <title>保险代理后台管理系统</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <!-- ================== BEGIN BASE CSS STYLE ================== -->
    <jsp:include page="../common/header.jsp"></jsp:include>
    <!-- ================== END BASE CSS STYLE ================== -->

    <!-- ================== 单独作用于本页表格td ================== -->
    <style>
        .table>tbody>tr>td {
            padding: 10px 15px;
            padding-top: 7px;
            padding-right: 15px;
            padding-bottom: 7px;
            padding-left: 15px;
        }
    </style>
    <!-- ================== 单独作用于本页表格td ================== -->

</head>
<body>
<!-- begin #page-loader -->
<div id="page-loader" class="fade in"><span class="spinner"></span></div>
<!-- end #page-loader -->

<!-- begin #page-container -->
<div id="page-container" class="fade page-sidebar-fixed page-header-fixed">
    <jsp:include page="../common/top.jsp"/>

    <!-- begin #sidebar -->
    <jsp:include page="../common/sitebar.jsp"/>
    <div class="sidebar-bg"></div>
    <!-- end #sidebar -->

    <!-- begin #content -->
    <div id="content" class="content">       
        <div class="row">
            <!-- begin col-12 -->
            <div class="col-md-12">
                <!-- begin panel -->
                <div class="panel panel-inverse">
                    <div class="panel-heading">
						身份证黑名单 
                    </div>
                    <div class="panel-body">
                    	<form class="form-horizontal">
                    	<input type="hidden" id="operator" name="operator" value="<shiro:principal property="realName" />">
							<div class="form-group">
                                    <label class="col-md-1 control-label">身份证</label>
                                    <div class="col-md-3">
                                        <input type="text" class="form-control" id="idCard" placeholder="身份证号">
                                    </div>
                                </div>
                          </form>    
                          <button type="button" onclick="search()" class="btn btn-primary m-r-5 m-b-5">查询</button>
                          <button type="button" onclick="reset()"class="btn btn-default m-r-5 m-b-5">重置</button>    
                        <div class="table-responsive">
                            <table id="blackidcardtable" style="width:1045px;" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th width="30%">身份证号</th>
                                    <th width="15%">数据来源</th>
                                    <th width="15%">黑名单状态</th>
                                    <th width="10%">操作</th>
                                </tr>
                                </thead>                            
                            </table>
                        </div>
                    </div>
                </div>
                <!-- end panel -->
            </div>
            <!-- end col-12 -->
        </div>
        <!-- end row -->
    </div>

    <!-- end #content -->

</div>
<!-- end page container -->
<jsp:include page="../common/footer.jsp"/>

<!-- ================== END PAGE LEVEL JS ================== -->

<script>

    $(document).ready(function() {
        App.init();
        TableManageFixedHeader.init();
    });

    var table;
    $(document).ready(function() {
        table = $("#blackidcardtable").DataTable( {
            "pagingType": "simple_numbers",//设置分页控件的模式
            searching: false,//屏蔽datatales的查询框
            aLengthMenu:[10],//设置一页展示10条记录
            "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
            "oLanguage": {  //对表格国际化
                "sLengthMenu": "每页显示 _MENU_条",
                "sZeroRecords": "没有找到符合条件的数据",
                //  "sProcessing": "&lt;img src=’./loading.gif’ /&gt;",
                "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                "sInfoEmpty": "没有记录",
                "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
                "sSearch": "搜索：",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"

                }
            },
            //"processing": true, //打开数据加载时的等待效果
            "serverSide": true,//打开后台分页
            'ordering':false,
            "ajax": {
                "url": "/sysidcard/queryTableData",
                "dataSrc": "aaData",
                "data": function ( params ) {                                      
             	   params.idCard=$('#idCard').val();//姓名
                }
            },
            "columns": [    
                         { "data": "idCard","bSortable": false},
                         { "data": "sourceStr","bSortable": false },
                         { "data": "status",
                      	   "render": function (data, type, full, meta) {
                      		 if(data==0)return "<span style='color:green;'>开启</span>";else if(data==1)return "<span style='color:red;'>关闭</span>";
                             return data;
                         } ,"bSortable": false}
                     ],
                     
                     "columnDefs" : [ {
                         "targets" : 3,//是操作按钮目标列
                         "data" : null,
                         "render" : function(data, type,row) {
                        	 var idCard = '"' + row.idCard + '"';
                        	 var source = '"' + row.source + '"';
                             var html = "";
                             if(row.status===0){
                          	   html+="<a href='javascript:void(0);' onclick='updateStatus("+ idCard +","+source+ ","+1+")' class='btn-link'>关闭</a>";
                             }else if(row.status==1){
                          	   html+="<a href='javascript:void(0);' onclick='updateStatus("+ idCard + ","+source+ ","+0+")' class='btn-link'>开启</a>";
                             }
                             return html;
                         }
                     } ]
        } );
    } );

  //重置
    function reset(){
    	$("#idCard").val("");
    }
  
    function search(){
        table.ajax.reload();
    }
    var flag = true;
    //修改状态
    function updateStatus(idCard,source,status) {
    	if(flag){
    		flag = false;
	    	jQuery.ajax({
	            type: "POST",
	            url: "/sysidcard/updateStatus",
	            data:{"idCard":idCard,"source":source,"status":status,"operator":$("#operator").val()},
	            dataType: "json",
	            success: function (data){
	                if (data.success == true) {
	                    alert('修改成功!');
	            		flag = true;
	                	table.ajax.reload();
	                } else {
	                    alert('修改失败!');
	                    flag = true;
	                }
	            }
	        });
    	}
    }

</script>
</body>
</html>
